let v = new Vue({
    el: '#app',
    data: {
        meeting:{
            title:'',
            content:'',
            startTime:'',
            endTime:'',
            deptId:1,
            deptName:'',
            makeUser:''
        },
        makeUsers:[],
        users:[],   //抄送人用户
        depts:{}    //部门信息
    },
    methods: {
        findDeptAll:function (){
            axios({
                url:`dept/findDeptAll`
            }).then(response=>{
                if (response.data.flag){
                    this.depts = response.data.data;
                    this.meeting.deptName=this.depts[0].deptName
                    this.selectUser(1);
                }
            })
        },
        selectUser:function (dId){
            axios({
                url:`user/findUserByDeptId/${dId}`
            }).then(response=>{
                $('#users').selectpicker('refresh');
                this.users = response.data.data;
            })
        },
        insertMeeting:function (){
            //处理抄送人
            let make = ''
            for (let i = 0; i < this.makeUsers.length; i++) {
                if (i === this.makeUsers.length-1){
                    make = make + this.makeUsers[i];
                }else{
                    make = make + this.makeUsers[i] + ",";
                }
            }
            this.meeting.makeUser = make;
            axios.post(`meeting/insertMeeting`,this.meeting)
                .then(rep=>{
                    if (rep.data.flag){
                        layer.msg("发布成功");
                    }else{
                        layer.msg("发布失败");
                    }
                }).catch(error=>{
                    layer.msg(error.message);
            })
        }
    },
    created: function () {
        this.findDeptAll();
    }
})